package pgpchat;

import java.net.Socket;

import pgpchat.pgp.PGPActor;
import pgpframework.Message.PGPMessage;

public class MessageActor {
	ChatPanel chatPanel;
	MsgListener servidorListener;
	Socket client;
	public PGPActor pGPActor;

	public MessageActor(Socket client, ChatPanel chatPanel, PGPActor pGPActor) {
		this.client = client;
		this.chatPanel = chatPanel;
		this.pGPActor = pGPActor;
		this.servidorListener = new MsgListener(client, this);
	}

	public void send(String msg) {
		PGPHelper.sendMsg(pGPActor.gerarMensagemPGP(msg), client);

	}

	public void receiveMsg(PGPMessage pgpMessage) {
		String msg = pGPActor.receivePGPMessage(pgpMessage);
		String previusTalk = this.chatPanel.txtConversa.getText();
		this.chatPanel.txtConversa.setText(previusTalk + "\n " + msg);
	}

	public void start() {
		new Thread(servidorListener).start();
	}

}
